package us.mooresr.geartrack.client.core.desktop;

import java.util.HashMap;
import java.util.List;

import us.mooresr.geartrack.shared.model.Person;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;

public class BorrowForm extends Composite {
	
	@UiField ListBox borrowerListBox;

	private static BorrowFormUiBinder uiBinder = GWT
			.create(BorrowFormUiBinder.class);
	
	private HashMap<Long, Integer> personMap;
	private HashMap<Integer, Long> personReverseMap;

	interface BorrowFormUiBinder extends UiBinder<Widget, BorrowForm> {
	}

	public BorrowForm() {
		initWidget(uiBinder.createAndBindUi(this));
		
		personMap = new HashMap<Long, Integer>();
		personReverseMap = new HashMap<Integer, Long>();
	}
	
	public void setPeople(List<Person> people) {
		borrowerListBox.clear();
		personMap.clear();
		personReverseMap.clear();
		
		Integer index = 1;
		
		for (Person p : people) {
			borrowerListBox.insertItem(p.getName(), -1);
			personMap.put(p.getId(), index);
			personReverseMap.put(index, p.getId());
			index++;
			
		}
		
	}
	
	public Long getPersonId() {
		Integer index = borrowerListBox.getSelectedIndex();
		
		if (index == null) {
			return null;
		} else {
			return personReverseMap.get(index);
		}
	}
	
	public void addPerson(Person person) {
		// TODO:  Implement this
		
	}
	
	public void deletePerson(Person person) {
		// TODO:  Implement this
	}
	
	public void changePerson(Person person) {
		// TODO:  Implement this
		
	}

}
